<?php
	///////////////////////
	// GLOBAL PARAMETERS //
	///////////////////////
	
	$intSpaceBetweenWorkAndHomeEmailX = 150;
	$intSpaceBetweenWorkAndMobNumX = 85;
	$intLineSepBetFmlySize = 30;
	$intSmallLineSepSize = 11;
	$intLineSepSize = 15;
	$intFirstNameIndentX = 145;
	$intMinLeftPositionX = 50;
	$intLeftDetailsIndentX = 40;
	$intLeftPhoneDetailsIndentX = 90;
	$intLeftEmailDetailsIndentX = 190;
	$intIndvRoleIndentX = 210;
	$intHomeTelephoneIndentX = 400;
	$intLeftIndvIndentX = 80;
	$intMinSepAfterAddrY = -1;    // spacing between families

	///////////////////////
	//   PAGE SIZE (A4)  //
	///////////////////////
	$intPageSizeY = 595;  // ISO Standard A4 width - landscape
	$intPageSizeX = 842;  // ISO Standard A4 length - landscape
	$intTopOfPageY = 560; // maximum top of page to use
	$intTopOfPageX = 45;  // minimum left of page to use
	$intMinBottomPageY = 20;  // minimum bottom of page to use
	$maxFamilySize = 20;

	$intLineAfterFamilyAdjustment = 5;
	$intTitleAboveLineAdjustment = 5;


	///////////////////////
	// LINE CONSTRAINTS  //
	///////////////////////
	$intLineSpaceToLeaveAtBothEnds = 40;
	$intLineSepLeftX = $intLineSpaceToLeaveAtBothEnds;
	$intLineSepRightX = $intPageSizeX - $intLineSpaceToLeaveAtBothEnds-10; // 595 is A4 page width

	$intVerticalLineSepX = 4;


	$intSurnamePosX = $intTopOfPageX+5;
	$intFirstNamePosX = $intTopOfPageX+70;
	$intSecondNamePosX = $intTopOfPageX+130;
//	$intGenderPosX = $intTopOfPageX+135;
//	$intRolePosX = $intTopOfPageX+167;
	$intAddr1PosX = $intTopOfPageX+200;
	$intSuburbPosX = $intTopOfPageX+310;
	$intPostcodePosX = $intTopOfPageX+395;
	$intHomePhonePosX = $intTopOfPageX+425;
	$intIntroChurchPosX = $intTopOfPageX+485;
	$intNotesPosX = $intTopOfPageX+605;

	$tmp_table = "tmp_table_new";
	
	
	$bShowTitlePage = FALSE;
	$bShowPageNumber = FALSE;

	
	//////////////////////////////////////////////////////
	// GPAC Database is Copyright 2002 Colin Todd       //
	// Written by Colin Todd - All rights reserved.     //
	//                                                  //
	// colintodd@myfastmail.com                         //
	//////////////////////////////////////////////////////

		$root = '../';
		include($root.'include/dbconnect.php');
		include($root .'include/config.php');
		include($root.'include/functions.php');

		$Indv_sql = html_entity_decode(@$_GET['indv_sql']);
		$Indv_sql = urldecode($Indv_sql);

		$Fmly_sql = html_entity_decode(@$_GET['fmly_sql']);
		$Fmly_sql  = urldecode($Fmly_sql);

		$bShowTitlePage = @$_GET['ShowTitlePage'];
		$bShowPageNumber = @$_GET['ShowPageNum'];
		$intPageCount = @$_GET['StartPageNum']-1; // set count to 0


// this code is not used
		$sql = "SELECT * FROM (((Individual INNER JOIN Family ON Individual.FamilyId = Family.FamilyId) LEFT JOIN Gender ON Individual.GenderCode = Gender.GenderCode) LEFT  JOIN Title ON Individual.Title = Title.Title) LEFT  JOIN RoleType ON Individual.RoleTypeCode = RoleType.RoleTypeCode WHERE $Indv_sql AND $Fmly_sql ORDER BY Surname limit 0,10";

	$sql_drop = "DROP TABLE IF EXISTS `$tmp_table`;";

	$result = mysql_query($sql_drop);
	if (!$result) {
	   die("line 97 query failed: ".mysql_error());
	}
//	echo "done drop table<p>";
//	echo mysql_num_rows($result)." rows affected Create<p>";


//	$where =  " AND Family.FamilyId=2";
	$where = " $Indv_sql AND $Fmly_sql ";
	$sql_create = "CREATE TEMPORARY TABLE $tmp_table SELECT Family.FamilyId, Individual.Surname,  Individual.FirstName AS MALE, Individual.FirstName AS FEMALE FROM Family INNER  JOIN Individual ON Family.FamilyId = Individual.FamilyId WHERE Individual.RoleTypeCode =  \"Head Of Family\" AND Individual.GenderCode =  \"F\" AND $where ;";
  
//		echo "<p>$sql_create <p><p>";
//		echo "<p>$where <p><p>";

		$result = mysql_query($sql_create);
		if (!$result) {
		   die("line 109 query failed: ".mysql_error());
		}
//		echo "<p>$sql_create</p>";
//		echo mysql_info()." rows affected Create<p>";



$sql_delete = "DELETE FROM $tmp_table";		
		$result = mysql_query($sql_delete );
		if (!$result) {
		   die("1 query failed: ".mysql_error());
		}
//		echo "<p>$sql_create</p>";
//		echo mysql_info()." rows affected Delete rows **<p>";



//echo "about to do create <p>";
	$sql_create = "INSERT INTO $tmp_table (`FamilyId`, `Surname`, `MALE`, `FEMALE`) SELECT Family.FamilyId,  Individual.Surname, NULL, Individual.FirstName AS FEMALE FROM Family INNER  JOIN Individual ON Family.FamilyId = Individual.FamilyId WHERE Individual.RoleTypeCode =  \"Head Of Family\" AND Individual.GenderCode =  \"F\" AND $where;";
//		echo "<p>$sql_create</p><p>";

		$result = mysql_query($sql_create);
		if (!$result) {
		   die("132 query failed: ".mysql_error());
		}
//		echo "<p>$sql_create</p>";
//		echo mysql_info()." rows affected Create ***<p>";








/*
INSERT INTO `tmp_table_new` ( `FamilyId` , `Surname` , `MALE` , `FEMALE` ) 
VALUES ( '6', 'ss', 'm', NULL);
*/
//	$sql_insert = "INSERT INTO $tmp_table ( `FamilyId`, `Surname`, `MALE` ) SELECT Family.FamilyId, Individual.Surname, Individual.FirstName FROM Family INNER JOIN Individual ON Family.FamilyId = Individual.FamilyId WHERE (((Individual.RoleTypeCode)=\"Head Of Family\") AND ((Individual.GenderCode)=\"M\")) $where;";


		

$sql_insert = "INSERT INTO $tmp_table SELECT Family.FamilyId, Individual.Surname, Individual.FirstName AS MALE, Null AS FEMALE FROM Family INNER JOIN Individual ON Family.FamilyId = Individual.FamilyId WHERE (((Individual.RoleTypeCode)=\"Head Of Family\") AND ((Individual.GenderCode)=\"M\")) AND $where;";		
		
		
		
		$result = mysql_query($sql_insert);
		if (!$result) {
		   die("2 query failed: ".mysql_error());
		}
//		echo "<p>$sql_insert</p>";
//		echo mysql_info()." rows affected Insert<p>";

	$sql_select = "SELECT *, FamilyId,  Surname, Max(MALE) AS MaleMember, Max(FEMALE) AS FemaleMember FROM $tmp_table GROUP BY FamilyId,  Surname ORDER BY Surname;";

		$result = mysql_query($sql_select);
		if (!$result) {
		   die("3 query failed: ".mysql_error());
		}
//		echo "<p>$sql_select</p>";
//		echo mysql_num_rows($result)." rows affected Select<p>";

//echo "<p>end!";
//exit;

/*

use the following query to make a temp table



// Access SQL
SELECT Family.*, Family.FamilyId, Family.FamilyShortName, Individual.Surname, NULL AS MALE, individual.FirstName AS FEMALE INTO query_tmp
FROM Family INNER JOIN individual ON Family.FamilyId=individual.FamilyId
WHERE individual.RoleTypeCode="Head Of Family" And individual.GenderCode="F";
// Access SQL


	$intSurnamePosX = $intTopOfPageX+5;
	$intFirstNamePosX = $intTopOfPageX+70;
	$intAddr1PosX = $intTopOfPageX+230;
	$intSuburbPosX = $intTopOfPageX+320;
	$intPostcodePosX = $intTopOfPageX+395;
	$intHomePhonePosX = $intTopOfPageX+425;


INSERT INTO abc ( FamilyId, FamilyShortName, Surname, MALE, FEMALE )
SELECT Family.FamilyId, Family.FamilyShortName, individual.Surname, individual.FirstName AS MALE, Null AS FEMALE
FROM Family INNER JOIN individual ON Family.FamilyId = individual.FamilyId
WHERE (((individual.RoleTypeCode)="Head Of Family") AND ((individual.GenderCode)="M"));



then do the following	query on the temp table

SELECT Query1_long.FamilyId, Query1_long.FamilyShortName, Query1_long.Surname, Max(Query1_long.MALE) AS MaxOfMALE, Max(Query1_long.FEMALE) AS MaxOfFEMALE
FROM Query1_long
GROUP BY Query1_long.FamilyId, Query1_long.FamilyShortName, Query1_long.Surname;

*/
	//  $sql = "SELECT * FROM (((Individual) LEFT JOIN Gender ON Individual.GenderCode = Gender.GenderCode) LEFT  JOIN Title ON Individual.Title = Title.Title) LEFT  JOIN RoleType ON Individual.RoleTypeCode = RoleType.RoleTypeCode  ORDER BY Individual.RoleTypeCode DESC, Individual.GenderCode DESC;";



	//     echo "<p>$sql<p>";
	   //$result = mysql_query($sql);

	   $resultsnumber = mysql_numrows($result);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	   

	$pdf = pdf_new();
	if (!pdf_open_file($pdf, "")) {
		print error;
		exit;
	};
	pdf_set_info($pdf, "Author", "Colin Todd");
	pdf_set_info($pdf, "Title", "Spreadsheet");
	pdf_set_info($pdf, "Creator", "Colin Todd");
	pdf_set_info($pdf, "Subject", "GPAC Database");
	// get and use a font object

//	$font1_normal = pdf_findfont($pdf, "Arial", "host", 1); 
//	$font = pdf_findfont($pdf, "Times New Roman", "winansi", 1);
//	$courier = pdf_findfont($pdf, "Courier", "host", 1); 
	$font1_normal_bold  = PDF_findfont($pdf,"Helvetica-Bold","host",0);
	$Helvetica  = PDF_findfont($pdf,"Helvetica","host",0);
	$font1_normal = $Helvetica  ;

//	PDF_set_parameter($pdf, "openaction", "fitwidth");
	PDF_set_parameter($pdf, "openaction", "fitpage");
	PDF_set_parameter($pdf, "openmode", "none");

	// initialise variables for start
	$intPageCount = 0; // set count to 0
	$y = $intMinBottomPageY-1 ; // set over limit so that new page (page1) will be inserted
	$x = $intTopOfPageX;

//	$top_lineY = 0;
//	$bot_lineY = 0;


	//pdf_setfont($pdf, $font1_normal, 20);
	//pdf_show_xy($pdf, "Number of results : $resultsnumber", $x, $y+15);

	




	while ($row = mysql_fetch_array($result)) { 
//		$y = $y - 5; // a small separator

		//
		// Grab Family details
		//



//	   $Indv_FamilyShortName = getFormattedFamilyShortName($FamilyId," ");
//	   $Fmly_ResAddress  = getFormattedResidentialAddress($FamilyId, chr(10),FALSE,FALSE,FALSE);
//	   $Fmly_HomePhone     = getFormattedHomePhoneNumber($FamilyId," ",FALSE, TRUE);
//	   $Fmly_Photo = $row["FamilyPhoto"];


		if (($y-$maxFamilySize)<$intMinBottomPageY){
			// insert new pagge
			// reset top values
			if($intPageCount == 0) 
			{
				// insert titlepage
				if($bShowTitlePage ) {
					if(trim($Indv_sql)=="TRUE") {
						$Indv_sql_ = "n/a";
					}else {
						$pos = strspn($Indv_sql, "TRUE   AND");
						$Indv_sql_ = substr($Indv_sql,$pos);
					}
					if(trim($Fmly_sql)=="TRUE") {
						$Fmly_sql_ = "n/a";
					}else {
//							$Fmly_sql_ = $Fmly_sql;
						$pos = strspn ($Fmly_sql, "TRUE   AND");
						$Fmly_sql_ = substr($Fmly_sql,$pos);
					}
					// insert titlepage
					printPDFTitlePage($pdf, "Family Listing", "Filtered by : ".$Indv_sql." and ".$Fmly_sql, $intPageSizeX , $intPageSizeY, $intTopOfPageX, $intTopOfPageY,$intMinBottomPageY, $font1_normal,$font1_normal_bold );
					$intPageCount++;

				}
			// don't end page
			} else
			{

				$top_lineY = $intTopOfPageY-$intLineAfterFamilyAdjustment;
				$bot_lineY = $y + $intLineSepSize - $intLineAfterFamilyAdjustment;

				// draw vertical lines
				//Left
				PDF_moveto($pdf,$intSurnamePosX - $intVerticalLineSepX ,$top_lineY );
				PDF_lineto($pdf,$intSurnamePosX - $intVerticalLineSepX ,$bot_lineY );
				PDF_stroke($pdf);
				//Right
				PDF_moveto($pdf,$intLineSepRightX ,$top_lineY);
				PDF_lineto($pdf,$intLineSepRightX ,$bot_lineY );
				PDF_stroke($pdf);
				//Column Uprights
				PDF_moveto($pdf,$intFirstNamePosX - $intVerticalLineSepX ,$top_lineY);
				PDF_lineto($pdf,$intFirstNamePosX - $intVerticalLineSepX ,$bot_lineY );
				PDF_stroke($pdf);
				PDF_moveto($pdf,$intSecondNamePosX  - $intVerticalLineSepX ,$top_lineY);
				PDF_lineto($pdf,$intSecondNamePosX  - $intVerticalLineSepX ,$bot_lineY );
				PDF_stroke($pdf);
//				PDF_moveto($pdf,$intRolePosX - $intVerticalLineSepX ,$top_lineY);
//				PDF_lineto($pdf,$intRolePosX - $intVerticalLineSepX ,$bot_lineY );
//				PDF_stroke($pdf);
				PDF_moveto($pdf,$intAddr1PosX - $intVerticalLineSepX ,$top_lineY);
				PDF_lineto($pdf,$intAddr1PosX - $intVerticalLineSepX ,$bot_lineY );
				PDF_stroke($pdf);
				PDF_moveto($pdf,$intSuburbPosX - $intVerticalLineSepX ,$top_lineY);
				PDF_lineto($pdf,$intSuburbPosX - $intVerticalLineSepX ,$bot_lineY );
				PDF_stroke($pdf);
				PDF_moveto($pdf,$intPostcodePosX - $intVerticalLineSepX ,$top_lineY);
				PDF_lineto($pdf,$intPostcodePosX - $intVerticalLineSepX ,$bot_lineY );
				PDF_stroke($pdf);
				PDF_moveto($pdf,$intHomePhonePosX - $intVerticalLineSepX ,$top_lineY);
				PDF_lineto($pdf,$intHomePhonePosX - $intVerticalLineSepX ,$bot_lineY );
				PDF_stroke($pdf);
				PDF_moveto($pdf,$intIntroChurchPosX  - $intVerticalLineSepX ,$top_lineY);
				PDF_lineto($pdf,$intIntroChurchPosX  - $intVerticalLineSepX ,$bot_lineY );
				PDF_stroke($pdf);
				PDF_moveto($pdf,$intNotesPosX - $intVerticalLineSepX ,$top_lineY);
				PDF_lineto($pdf,$intNotesPosX - $intVerticalLineSepX ,$bot_lineY );
				PDF_stroke($pdf);
				
				// Left footer
				pdf_show_xy($pdf, "Family & Head Of Family Listing", $intTopOfPageX, $intMinBottomPageY);
				// Middle footer
				pdf_show_xy($pdf, "Page $intPageCount", $intPageSizeX/2-($intTopOfPageX), $intMinBottomPageY);
				// Right footer
				pdf_show_xy($pdf, date("g:i a F j, Y"), ($intPageSizeX-$intTopOfPageX)-100, $intMinBottomPageY);

				pdf_end_page($pdf);
	
			}
			// start a new page (A4)
			pdf_begin_page($pdf, $intPageSizeX , $intPageSizeY );
			$intPageCount++;
//			pdf_add_outline($pdf, "Page $intPageCount");
			pdf_setfont($pdf, $font1_normal, 10);
			// reset X,Y values to defaults
			$y = $intTopOfPageY;
			$x = $intTopOfPageX;

			// test coordinates
			pdf_setfont($pdf, $font1_normal, 8);
//			pdf_show_xy($pdf, "$x..$y", $x-40, $y);

			pdf_setfont($pdf, $font1_normal_bold, 8);
			// insert new top line to page
			pdf_show_xy($pdf, "Surname", $intSurnamePosX , $y );
			pdf_show_xy($pdf, "Male", $intFirstNamePosX , $y);
			pdf_show_xy($pdf, "Female", $intSecondNamePosX , $y);
//			pdf_show_xy($pdf, "Sex", $intGenderPosX , $y);
			pdf_show_xy($pdf, "Address", $intAddr1PosX , $y);
			pdf_show_xy($pdf, "City", $intSuburbPosX , $y);
			pdf_show_xy($pdf, "Zip", $intPostcodePosX , $y);
			pdf_show_xy($pdf, "HomePhone", $intHomePhonePosX , $y);
			pdf_show_xy($pdf, "Introchurch", $intIntroChurchPosX , $y);
			pdf_show_xy($pdf, "Notes", $intNotesPosX , $y);

		
			PDF_moveto($pdf,$intSurnamePosX - $intVerticalLineSepX ,$y - $intLineAfterFamilyAdjustment );
			PDF_lineto($pdf,$intLineSepRightX ,$y - $intLineAfterFamilyAdjustment );
			PDF_stroke($pdf);

			$y = $y - $intLineSepSize;
		}
		else
		{
			// then OK to print
			// $y = $y - $intLineSepSize;
		}

		pdf_setfont($pdf, $font1_normal, 8);
//		pdf_show_xy($pdf, "$x..$y", $x-40, $y);

	   $FamilyId = $row["FamilyId"];
//SELECT 

$Fmly_result = mysql_query("Select * from Family where FamilyId=$FamilyId;");
$Fmly_row = mysql_fetch_array($Fmly_result);

//	   $IndividualId = $row["IndividualId"];
//	   $FirstName = $row["FirstName"];
	   $Female = $row["FemaleMember"];
	   $Male= $row["MaleMember"];
	   $Surname = $row["Surname"];
//       $Role = $row["RoleTypeCode"];
//	   $Gender = $row["GenderCode"];

	   
	   $AddressLine1 = getFormattedResidentialAddress($FamilyId, " ", TRUE, FALSE, TRUE, TRUE, FALSE, "", TRUE, TRUE);

//function getFormattedResidentialAddress($FID, $delim, $bUseAbbrevCodes, $bInclCountry, $bExclAUCountry, $bFirstLineOnly = FALSE, $bMouseOverCode=FALSE, $strReplaceIfPrivate = "", $bHidePrivate = TRUE, $bHidePropName = FALSE)


//1135

//echo "$AddressLine1 ";
//exit;
	   $Suburb= $Fmly_row["ResidentialSuburb"];
	   $Postcode = $Fmly_row["ResidentialPostcode"];
	   $HomePhone =  getFormattedHomePhoneNumber($FamilyId, " ", FALSE, FALSE, FALSE, "PRIVATE");
//	   $WorkPhone = getFormattedWorkPhoneNumber($IndividualId,    " ", FALSE, FALSE, FALSE, "PRIVATE");
//	   $MobilePhone = getFormattedMobilePhoneNumber($IndividualId," ", FALSE, FALSE,  "PRIVATE");

		pdf_setfont($pdf, $font1_normal, 8);
		pdf_show_xy($pdf, $Surname, $intSurnamePosX , $y);
		pdf_show_xy($pdf, $Male, $intFirstNamePosX , $y);
		pdf_show_xy($pdf, $Female, $intSecondNamePosX, $y);
		pdf_add_outline($pdf, "$Male $Surname");

//		pdf_show_xy($pdf, $Role, $intRolePosX , $y);
//		pdf_show_xy($pdf, $Gender, $intGenderPosX , $y);
		pdf_show_xy($pdf, $AddressLine1, $intAddr1PosX , $y);
		pdf_show_xy($pdf, $Suburb, $intSuburbPosX , $y);
		pdf_show_xy($pdf, $Postcode, $intPostcodePosX , $y);
		pdf_show_xy($pdf, $HomePhone, $intHomePhonePosX , $y);
//		pdf_show_xy($pdf, $WorkPhone, $intWorkPhonePosX , $y);
//		pdf_show_xy($pdf, $MobilePhone, $intMobilePhonePosX , $y);
			

//		pdf_show_xy($pdf, "".strtoupper($Indv_FamilyShortName)."", $x, $y);
//		pdf_show_xy($pdf, "".$Fmly_HomePhone."", $x+$intHomeTelephoneIndentX, $y);

		pdf_setfont($pdf, $font1_normal, 10);
		$intTopOfAddressY = $y-$intLineSepSize;

		//
		// Insert line at end of Family
		//

		PDF_moveto($pdf,$intSurnamePosX - $intVerticalLineSepX ,$y - $intLineAfterFamilyAdjustment );
		PDF_lineto($pdf,$intLineSepRightX ,$y - $intLineAfterFamilyAdjustment );
		PDF_stroke($pdf);
		$y = $y - $intLineSepSize;
	
		//pdf_show_xy($pdf, "$x..$y", $x-10, $y);

	} // end while family
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



	//pdf_setfont($pdf, $font, 12); // font size 12

	// add an image under the text
//	$image = pdf_open_image_file($pdf, "gif", "../include/logoB.gif");
	//pdf_place_image($pdf, $image, 50, 650, 0.25);


	/*
	$y = 800;
	$x = 40;
	while ($x < 300){
		pdf_show_xy($pdf, "Colin ($x, $y)", $x, $y);
		$x = $x + 80;
	}
	$x = 50;
	$y = 720;
	while ($y > 300){
		pdf_show_xy($pdf, "Todd ($x, $y)", $x, $y);
		pdf_place_image($pdf, $image, $x+100, $y, .5); // last arg is scalling facter. 1 = 1:1

		$y = $y - 50;
	}


	//pdf_show_xy($pdf, "Nedxt line 1 2 3 4 5 6 7 8 9", 1, 1);
	pdf_moveto($pdf, 50, 740);
	pdf_lineto($pdf, 330, 740);
	pdf_stroke($pdf);
	*/

	// set a colour for the line
	//pdf_setcolor($pdf, "stroke", "rgb", 0, 0, 0);

	// place a logo in the top left corner
	//$image = pdf_open_image_file($pdf, "gif", "include/logo.gif");
	//pdf_place_image($pdf, $image, 50, 785, 0.5);

	// draw a line under the logo
	//pdf_moveto($pdf, 20, 780);
	//pdf_lineto($pdf, 575, 780);
	//pdf_stroke($pdf);

	// draw another line near the bottom of the page pdf_moveto($pdf, 20, 50); 
	//pdf_lineto($pdf, 575, 50); 
	//pdf_stroke($pdf);

	// and write some text under it
	//pdf_show_xy($pdf, "Confidential and proprietary", 200, 35);
	pdf_set_value($pdf, "textrendering", 0);

	// draw vertical lines
	$top_lineY = $intTopOfPageY-$intLineAfterFamilyAdjustment;
	$bot_lineY = $y + $intLineSepSize - $intLineAfterFamilyAdjustment;
	//Left
	PDF_moveto($pdf,$intSurnamePosX - $intVerticalLineSepX ,$top_lineY );
	PDF_lineto($pdf,$intSurnamePosX - $intVerticalLineSepX ,$bot_lineY );
	PDF_stroke($pdf);
	//Right
	PDF_moveto($pdf,$intLineSepRightX ,$top_lineY);
	PDF_lineto($pdf,$intLineSepRightX ,$bot_lineY );
	PDF_stroke($pdf);
	//Column Uprights
	PDF_moveto($pdf,$intFirstNamePosX - $intVerticalLineSepX ,$top_lineY);
	PDF_lineto($pdf,$intFirstNamePosX - $intVerticalLineSepX ,$bot_lineY );
	PDF_stroke($pdf);
	PDF_moveto($pdf,$intSecondNamePosX - $intVerticalLineSepX ,$top_lineY);
	PDF_lineto($pdf,$intSecondNamePosX - $intVerticalLineSepX ,$bot_lineY );
	PDF_stroke($pdf);
//	PDF_moveto($pdf,$intRolePosX - $intVerticalLineSepX ,$top_lineY);
//	PDF_lineto($pdf,$intRolePosX - $intVerticalLineSepX ,$bot_lineY );
//	PDF_stroke($pdf);
	PDF_moveto($pdf,$intAddr1PosX - $intVerticalLineSepX ,$top_lineY);
	PDF_lineto($pdf,$intAddr1PosX - $intVerticalLineSepX ,$bot_lineY );
	PDF_stroke($pdf);
	PDF_moveto($pdf,$intSuburbPosX - $intVerticalLineSepX ,$top_lineY);
	PDF_lineto($pdf,$intSuburbPosX - $intVerticalLineSepX ,$bot_lineY );
	PDF_stroke($pdf);
	PDF_moveto($pdf,$intPostcodePosX - $intVerticalLineSepX ,$top_lineY);
	PDF_lineto($pdf,$intPostcodePosX - $intVerticalLineSepX ,$bot_lineY );
	PDF_stroke($pdf);
	PDF_moveto($pdf,$intHomePhonePosX - $intVerticalLineSepX ,$top_lineY);
	PDF_lineto($pdf,$intHomePhonePosX - $intVerticalLineSepX ,$bot_lineY );
	PDF_stroke($pdf);
	PDF_moveto($pdf,$intIntroChurchPosX  - $intVerticalLineSepX ,$top_lineY);
	PDF_lineto($pdf,$intIntroChurchPosX  - $intVerticalLineSepX ,$bot_lineY );
	PDF_stroke($pdf);
	PDF_moveto($pdf,$intNotesPosX - $intVerticalLineSepX ,$top_lineY);
	PDF_lineto($pdf,$intNotesPosX - $intVerticalLineSepX ,$bot_lineY );
	PDF_stroke($pdf);

	// Left footer
	pdf_show_xy($pdf, "Full Individual Listing", $intTopOfPageX, $intMinBottomPageY);
	// Middle footer
	pdf_show_xy($pdf, "Page $intPageCount", $intPageSizeX/2-($intTopOfPageX), $intMinBottomPageY);
	// Right footer
	pdf_show_xy($pdf, date("g:i a F j, Y"), ($intPageSizeX-$intTopOfPageX)-100, $intMinBottomPageY);



	pdf_end_page($pdf);
	pdf_close($pdf);
	//pdf_delete($pdf);

	$buf = pdf_get_buffer($pdf);
	$len = strlen($buf);

	header("Content-type: application/pdf");
	header("Content-Length: $len");
	header("Content-Disposition: inline; filename=foo.pdf");
	print $buf;

	pdf_delete($pdf);

?>